mde.tw

  • Home
    • Site Map
    • reveal
    • blog
  • 程式
    • cp2022
      • cp-syllabus
    • wcm2023
    • cmsimde
      • Portable Python
      • Token and SSH
      • Bootstrap
      • Bugs
      • Frameworks
    • Problem solving
    • Programming
      • Computer
      • Program
      • Python
      • ANSIC
      • Rust
      • Carbon
    • TCExam
      • sendmail
    • Three.js
    • ffmepg
    • Pandoc
    • VSCode
    • Powershell
    • Blockchain
  • Brython
    • Unitconvert
    • Game
    • Simulator
    • Algorithms
  • CPython
    • Pybean
    • PDF
    • RoboDK
    • CAD
      • Python for SW
      • Python for INV
      • Python for NX
    • CAE
    • BS4
    • PostgreSQL
    • PyQt
    • MS Graph
      • MS Teams
  • 設計
    • cad2022
      • cad-syllabus
    • cd2023
    • ME
      • Trends
      • Gears
      • Robots
      • Vehicle
      • Aircraft
      • 3D print
      • Computer Vision
      • Industry 4.0
    • Reference
      • Portable NX1980
      • template and SSH
      • Pull Requests
      • Resolve Conflicts
      • Revealjs
      • Virtualbox
      • cube
    • Solvespace
    • Realizable
    • Bash
    • Leo Editor
    • Fossil SCM
    • Classroom
    • Gazebo
    • Webots
    • Deep RL
  • NX
    • NX1980_setup
    • NX2206
    • NXOpen
    • Mechatronics
  • CoppeliaSim
    • Lua
    • Foosball
    • Examples
      • ZeroMQ
    • Mujoco
    • ROS
  • Projects
    • Wink
    • pjcopsim
      • Copsim Doc
      • Webots Doc
    • pjgazebo
    • pjcontrol
    • pjgithub
    • pjexam
    • pyslvs
    • pjfem
    • pjblender
    • OpenTextbooks
Python for SW << Previous Next >> Python for NX

Python for INV

針對 HW1 使用 AutoDesk Inventor 2019 教育版繪零件圖者, 可以利用下列 Python 程式修改零件參數, 取零件影像圖並計算零件體積:

import pythoncom
import win32com.client
import win32api
import os
 
# Open Inventor
invApp = win32com.client.Dispatch("Inventor.Application")
#print(invApp)
invApp.Visible = True
 
invApp.SilentOperation = True
 
# Set location of assembly
partName = 'C:/tmp/Part1.ipt'
 
# Open the model
oDoc = invApp.Documents.Open(partName)
# use UserParameters to access the user parameters
#oUserParams = oDoc.ComponentDefinition.Parameters.UserParameters
#oNewParam = oUserParams.AddByExpression("x", "9", "mm")
# use Item() to get the model parameter named "d0"
d0 = oDoc.ComponentDefinition.Parameters.Item("d0")
# Expression can add dimension unit
#d0.Expression = "2 cm"
# Value use the default system unit: cm
d0.Value = 2
# use Update() method to get the new part volume
oDoc.Update()
# fit the active view and save the part image
invApp.ActiveView.Fit(True)
oDoc.SaveAs("C:/tmp/Part1.png", True)
print(oDoc.ComponentDefinition.MassProperties.Volume)
#invApp.Quit()


Python for SW << Previous Next >> Python for NX

Copyright © All rights reserved | This template is made with by Colorlib